/*
 * @Author: Trae AI
 * @Date: 2024-05-14
 * @LastEditors: Trae AI
 * @LastEditTime: 2024-05-14
 * @Description: 脚本模型
 */

class ScriptModel {
  final String name;
  final String path;
  final String description;

  ScriptModel({
    required this.name,
    required this.path,
    required this.description,
  });

  // 从JSON创建模型
  factory ScriptModel.fromJson(Map<String, dynamic> json) {
    return ScriptModel(
      name: json['name'] as String,
      path: json['path'] as String,
      description: json['description'] as String,
    );
  }

  // 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'name': name,
      'path': path,
      'description': description,
    };
  }
}

// 脚本参数模型
class ScriptParams {
  final String projectType;
  final String templateType;
  final String projectName;
  final String packageName;
  final String displayName;
  final String outputDir;

  ScriptParams({
    required this.projectType,
    required this.templateType,
    required this.projectName,
    required this.packageName,
    required this.displayName,
    required this.outputDir,
  });

  // 从JSON创建模型
  factory ScriptParams.fromJson(Map<String, dynamic> json) {
    return ScriptParams(
      projectType: json['project_type'] as String,
      templateType: json['template_type'] as String,
      projectName: json['project_name'] as String,
      packageName: json['package_name'] as String,
      displayName: json['display_name'] as String,
      outputDir: json['output_dir'] as String,
    );
  }

  // 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'project_type': projectType,
      'template_type': templateType,
      'project_name': projectName,
      'package_name': packageName,
      'display_name': displayName,
      'output_dir': outputDir,
    };
  }

  // 转换为命令行参数格式
  String toCommandParams() {
    return [
      'project_type=$projectType',
      'template_type=$templateType',
      'project_name=$projectName',
      'package_name=$packageName',
      'display_name=$displayName',
      'output_dir=$outputDir',
    ].join('\n');
  }
}
